package com.anxin.act.model.vo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.activiti.engine.repository.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

/**
 * @author: liuxiangyu
 * @date: 2020/3/5 15:55
 */
public class ActModelVo {

    private static Logger logger = LoggerFactory.getLogger("sys-error");

    //模型ID
    private String id;

    //模型名称
    private String name;

    //模型Key
    private String key;

    //模型分类
    private String category;

    private String formType;

    private String formId;


    private boolean copyModel;


    public String getFormType() {
        return formType;
    }

    public void setFormType(String formType) {
        this.formType = formType;
    }

    public String getFormId() {
        return formId;
    }

    public void setFormId(String formId) {
        this.formId = formId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean getCopyModel() {
        return copyModel;
    }

    public void setCopyModel(boolean copyModel) {
        this.copyModel = copyModel;
    }

    public ActModelVo(){

    }

    public ActModelVo(Model model){
        this.key=model.getKey();
        this.name=model.getName();
        this.category=model.getCategory();
        this.id=model.getId();

        if(!StringUtils.isEmpty(model.getMetaInfo())) {
            try {
                JsonNode responseJSON = new ObjectMapper().readTree(model.getMetaInfo());

                JsonNode formTypeNode = responseJSON.get("formType");
                if (formTypeNode != null){
                    this.formType = formTypeNode.textValue();
                }

                JsonNode formId = responseJSON.get("formId");
                if (formId != null){
                    this.formId = formId.textValue();
                }

            } catch (JsonProcessingException e) {
                logger.error("ActModelVo有参构造异常", e);
            }
        }


    }
}
